<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>用户列表</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <!-- 引入 Bootstrap -->
    <link href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
    <style>
        .red{
            color: red;
        }
    </style>
</head>
<body>
<button onclick="window.history.back();" value="回退">回退</button>
<a href="${pageContext.request.contextPath}/user/tologin">回到主页</a>

<div class="container">

    <div class="row clearfix">
        <div class="col-md-12 column">
            <div class="page-header">
                <h1>
                    <small>用户列表--显示所有用户</small>
                </h1>
            </div>
        </div>
    </div>

    <div class="row">
        <div class="col-md-4 column">

            <a class="btn btn-primary" href="${pageContext.request.contextPath}/user/toadduser">用户注册</a>
        </div>
    </div>

    <button onclick="window.history.back();" value="回退">回退</button>


    <form class="layui-form layui-form-pane">
        <div class="layui-form-item">
            <label class="layui-form-label">
                <%--                 <i class="layui-icon layui-icon-search"></i>--%>
                <input type="button" onclick="xx()" value="搜索"/>
            </label>
            <div class="layui-input-block">
                <input id="searchInput" type="text" name="search_data" autocomplete="off"
                       placeholder="请输入关键字搜索" class="layui-input">

            </div>
        </div>
    </form>

    <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.js"></script>


    <%--
        <div class="row">
            <div class="col-md-4 column">

                <a class="btn btn-primary" href="${pageContext.request.contextPath}/user/todeleteuser">删除用户</a>
            </div>
        </div>
        <div class="row">
            <div class="col-md-4 column">

                <a class="btn btn-primary" href="${pageContext.request.contextPath}/user/toupdateuser">更新用户</a>
            </div>
        </div>
    --%>


    <div class="row clearfix">
        <div class="col-md-12 column">
            <table class="table table-hover table-striped">
                <thead>
                <tr>
                    <th>用户账号</th>
                    <th>用户密码</th>
                    <th>用户姓名</th>
                    <th>用户性别</th>
                    <th>用户电话</th>
                    <th>用户部门</th>
                    <th>用户住址</th>
                    <th>用户电子邮箱</th>
                    <th>操作</th>


                </tr>
                </thead>

                <tbody id="userList">
                <c:forEach var="user" items="${user}">
                    <tr class="trclass">
                        <td class="userIdClass">${user.userId}</td>
                        <td>${user.userPassword}</td>
                        <td>${user.username}</td>
                        <td>${user.usersex}</td>
                        <td>${user.userphone}</td>
                        <td>${user.userdepartment}</td>
                        <td>${user.useraddress}</td>
                        <td>${user.useremail}</td>
                        <td><input type="button" value="删除" onclick="openResult('${user.userId}')"/> <a
                                href="${pageContext.request.contextPath}/user/toupdateuser">
                            <button>修改</button>
                        </a></td>
                            <%--<input type="button" value="修改" onclick="javascript: top.location.href = '/updateuser?userId=${user.user}'"/></td>--%>
                    </tr>
                </c:forEach>
                <script>
                    function xx() {
                        let searchValue = $("#searchInput").val();
                        console.log(searchValue)
                        $(".trclass").each(function (){
                            let id = $(this).find(".userIdClass").text();
                            console.log(id)
                            $(this).removeClass("red");
                            if(id == searchValue){
                                $(this).addClass("red");
                            }
                        })
                        console.log($("#userList"));
                    }
                </script>
                </tbody>
            </table>
        </div>
    </div>
</div>
<script>

    function openResult(userId) {
        if (confirm("请注意：您确定要删除整条数据吗？")) {　　//否则如果 满足条件 弹出确认框！
            top.location.href = 'deleteuser?userId=' + userId;
        } else {　//如果点了取消
            alert("取消");
            return false;
        }
    }


</script>
